﻿namespace Example
{
    using System;

    using MvcRouteUnitTester;

    using Xunit;
    using Xunit.Extensions;

    public sealed class MvcApplicationFacts
    {
        [Theory]
        [InlineData("/", "Home", "Index")]
        [InlineData("/Example", "Example", "Index")]
        [InlineData("/Example/Index", "Example", "Index")]
        [InlineData("/Foo/Bar", "Foo", "Bar")]
        public void op_RegisterRoutes_RouteCollection(string url, 
                                                      string controller, 
                                                      string action)
        {
            new RouteTester<MvcApplication>()
                .WithIncomingRequest(url)
                .ShouldMatchRoute(controller, action);
        }

        [Fact]
        public void op_RegisterRoutes_RouteCollectionNull()
        {
            Assert.Throws<ArgumentNullException>(() => MvcApplication.RegisterRoutes(null));
        }

        [Fact]
        public void op_RegisterRoutes_RouteCollection_whenIgnore()
        {
            var tester = new RouteTester<MvcApplication>();

            tester.WithIncomingRequest("/handler.axd/pathInfo").ShouldBeIgnored();
        }

        [Theory]
        [InlineData("/Foo/Bar/5", "Foo", "Bar", "5")]
        public void op_RegisterRoutes_RouteCollection_whenParameter(string url, 
                                                                    string controller, 
                                                                    string action, 
                                                                    string id)
        {
            var values = new
                             {
                                 id
                             };
            new RouteTester<MvcApplication>()
                .WithIncomingRequest(url)
                .ShouldMatchRoute(controller, action, values);
        }

        [Theory]
        [InlineData("/Foo/Bar/5/Baz")]
        public void op_RegisterRoutes_RouteCollection_whenUnmatched(string url)
        {
            new RouteTester<MvcApplication>()
                .WithIncomingRequest(url)
                .ShouldMatchNoRoute();
        }
    }
}